from playwright.sync_api import sync_playwright

from utils import RedisHelper
from pjstealth import stealth_sync


class GetHelper:
    def __init__(self):
        self.ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.5504.116 Safari/537.36 Edg/101.0.1210.47"
        self.proxies = None
        self.redis_client = RedisHelper().get_conn()

    def on_response(self, response):
        print(response.url)



    def main(self, url):
        with sync_playwright() as p:
            browser = p.chromium.launch(headless=True, proxy=self.proxies if self.proxies else None)
            context = browser.new_context(user_agent=self.ua, accept_downloads=True)
            page = context.new_page()
            stealth_sync(page)
            page.on('response', self.on_response)
            page.goto("https://store.gx.me" + url)
            page.wait_for_load_state('networkidle')
            input(111111111111)
            html = page.content()
            page.close()
            context.close()
            browser.close()
            return html

if __name__ == '__main__':
    GetHelper().main("/mods/t92zu9/ryuk-the-shinigami/")
